Repository navigation
fix(updates): harden upgrade runs after review - #13463
Merged
Merged
Conversation
…es out StartOne returns after its wait with the state of the item. When the operation was not accepted yet, the item has no job and is not terminal. The single upgrade routes and the Assistant only handled a terminal item, so they answered "started" with an empty job ID. SingleOutcome maps the item to a job, a refusal or a pending start, and every caller of StartOne uses it: the two backend upgrade routes, the model upgrade route, the add-on upgrade route and the in-process client. A pending start answers 202 with code pending, the run ID and the run. The Assistant gets an error that names the run to follow, never a job. The HTTP client of the tools reads the same 202 answer. Assisted-by: Claude:claude-opus-5-5
The upgrade route recorded the owner's operation ID in a map of its own process. When another frontend took the run over, its starter found no ID and sent a second update-queue, which the owner refused as upgrade_conflict. The first record stayed accepted and the add-on stayed blocked. A cancelled or skipped item, or a start that failed after the route stopped waiting, also left the record accepted. The route now passes the operation ID as extra data of the start item, which the run stores with the item (operation_id). The add-on starter hands it to the upgrader, which runs that record instead of recording a new one. As an observer of the runs, the upgrader drops the record of an add-on item that ended without starting it. Assisted-by: Claude:claude-opus-5-5
When a user cancelled an upgrade after the swap and the previous build could not be put back, rollbackError returned the cancel joined with the restore error. The operation queue checks for a cancel first, so it reported the operation as cancelled although the backend was left on the failed build. rollbackError now checks the restore error first and returns an upgrade error that carries ErrUpgradeRestore, with the cause kept in the chain. The operation queue reports such an error as a failure. The restore messages name the backend directory by its base name, not by its path. Assisted-by: Claude:claude-opus-5-5
A failed restore and the leftover sweep at start keep the backup directory of a swap on purpose: it can be the last build that worked. The next install or upgrade then deleted it without a check before it started its own swap. Install and upgrade now move a previous build they find at the backup path to "<backup>.kept-<time>", and refuse to start when they cannot move it. The listing and the leftover sweep leave the kept copy alone. The removal of the replaced build after a successful install logs its error, and a failed registration without a start check keeps the replaced build. Assisted-by: Claude:claude-opus-5-5
A worker that does not serve backend.upgrade answers that it does not know the verb. The frontend wrapped that answer as ErrNoRoute, so the backend manager marked the node unhealthy and counted a failed attempt of the pending upgrade, although the worker is present. The answer is now ErrWorkerTooOld. The node stays healthy, and the pending upgrade waits fifteen minutes without counting an attempt. The distributed seams guide says so and no longer says that an upgrade falls back to the install subject. Assisted-by: Claude:claude-opus-5-5
…nner The install route kept its guard against two installs of one backend name in a map of its own closure, and the library items of upgrade runs had their own copy of the install job with no guard. A run that upgraded src/foo and an administrator who installed foo from the library could write one directory at the same time. The run's copy had also drifted from the route: raw step names, the raw error text and a two hour timeout, while its comment said it did what the route does. backendlib.JobRunner now owns the job and the guard. The install route, the library items of upgrade runs and the Assistant's library install use the runner of the application, so one install of a backend name runs at a time on a node. Each job writes the step messages and the reasons of the route, registers its cancel and drops it when it ends, and runs for at most one hour. The install route and the Assistant's install refuse with run_active while an upgrade run runs. Assisted-by: Claude:claude-opus-5-5
A frontend that lost the lock of a run (a lost database session) stops its runner, but the gallery operations it started go on. The frontend that took the run over made every busy item unconfirmed and checked it at once. The check still listed an item whose download was running, so the item failed as interrupted although the download finished later, and a retry started a second upgrade of the same backend. The takeover now keeps a running item whose operation still has a status in the running phase and follows it; only the items without a status are checked. The new runner claims the run in the store before it reads it, and a save of the runner that lost the run is refused (ErrUpgradeRunFenced), so that runner stops without writing. Assisted-by: Claude:claude-opus-5-5
A run was written to the store first and its lock was taken after. The sweep of another frontend does not take the admission lock, so in that window it could take the new run over, and its recovery failed the fresh running items as interrupted. create now takes the lock of the run, with an ID made in advance, before it writes the row. Assisted-by: Claude:claude-opus-5-5
The process of a backend start check was registered with the watchdog like a loaded backend. While the check ran it counted for the LRU limit, and with no request time it was the first pick for an eviction. Each started process also added a termination handler that was never removed, so every check left one behind. The start check now drops its process from the watchdog as soon as it starts. RegisterGracefulTerminationHandler returns a function that removes the handler, and a backend process removes its handler when it exits. Assisted-by: Claude:claude-opus-5-5
…racters The key pattern of Redact started with a word boundary. "_" is a word character, so HF_TOKEN=, OPENAI_API_KEY= and AWS_SECRET_ACCESS_KEY= never matched. A JSON field such as "password":"x" did not match either, and a bare GitHub, Hugging Face or OpenAI style token or a JWT was kept. The key now starts the text or follows a character that is not a letter or a digit, may carry a prefix joined by "_" or "-", and may be closed by a quote. Known token shapes are removed by their shape. A value that is only digits is kept, so a count such as max_tokens=512 stays. JoinLines dropped the escape character before it removed the terminal escapes, so "[31m" remained. It now removes the escapes first. JoinLines and Text also drop format characters (a bidirectional override, a zero width character), which can make a text read differently. Assisted-by: Claude:claude-opus-5-5
On a server that runs its backends itself, the end of the output of a build that did not start went to the operation status, /api/operations, the run and the inbox with control characters removed only. A path or a token that the process printed reached them, and so did the path of the run file in the error of a process that could not start. The tail of the output and the text of StartCheckError are now cleaned with sanitize.Text: paths are cut to their file name and what looks like a credential is removed. Assisted-by: Claude:claude-opus-5-5
Item.Verifying was not in the JSON of a run, so the page treated every unconfirmed item as ended. While the server checked an item after a restart, the progress bar counted it as done, the strip counted it as running only because the run was active, and "waiting for X" skipped it. An unconfirmed item that no check could answer, in a run that still had other items going, was shown as checking. The item now carries "verifying" in its JSON. The page has isBusy, the same rule as Item.Busy on the server: running, or unconfirmed while the server checks it. isEnded, needsAttention, the progress, the strip counts and the row use it. Assisted-by: Claude:claude-opus-5-5
A poll that left before a cancel and came back after it overwrote the answer of the cancel, so the strip showed the run running again. The poll effect also depended on the run, so every answer rebuilt the interval, and the end of a run could be told twice. Every request that answers a run now takes a number when it is asked, and the reducer drops an answer older than the one it shows. The poll interval no longer depends on the run, and the end of a run is told once for each run. Assisted-by: Claude:claude-opus-5-5
A takeover follows an item whose operation still has a status. When the frontend that ran the run died, the other frontends keep the last status it broadcast, and the run would follow that dead operation until the stale operation reaper failed it. The runner now checks such an item once its status shows no change for RecoveredIdleAfter (two minutes by default): its outcome counts as lost and a fresh check decides, as before the takeover followed live items. A download that goes on changes its status and stays followed. Assisted-by: Claude:claude-opus-5-5
The inbox observer was added after the goroutine of the upgrade run service started. Its first sweep can take over a run at once, so the first change of that run could reach no observer. The service pointer was also written without synchronization while other goroutines read it. The observers are now part of upgraderun.Options, so the service has them before it runs, and the application keeps the service in an atomic.Pointer. Assisted-by: Claude:claude-opus-5-5
…ines The runner started the start of an operation, its cancel and the fresh check on goroutines that the service did not count. Close returned while they still ran, and a start could finish after the service stopped. The runner now counts them in the wait group of the service. Assisted-by: Claude:claude-opus-5-5
The end notification of a run put the name of the first item that needs attention into its body as it was. The parameter of the same name was already cleaned. The body now uses sanitize.OneLine as well, so control characters, escapes and new lines in a title do not reach the inbox or a push service. Assisted-by: Claude:claude-opus-5-5
ValidateBackendName accepted names that end in .backup, .install-backup, .upgrade-tmp, .install-tmp, .failed or a kept previous build. The listing skips such a directory, and an install or an upgrade of another backend would take it for its own backup or staging. Assisted-by: Claude:claude-opus-5-5
When the preview of a review failed, the dialog showed the load error and, from the same state, the refusal callout of a start, so the reason appeared twice. The refusal callout now shows only for a review that loaded. Assisted-by: Claude:claude-opus-5-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #13447. A review of the merged upgrade run code found defects in
the failure and multi-frontend paths. Each fix has a test that failed first.
Fixes
upgrade routes, the model route, the Assistant tools and the add-on route
use one helper. When the run has not started the item yet, they answer
202with{code: "pending", run_id, run}, and the Assistant says so.operation ID is kept in the run item, not in per-process memory. The record
is dropped when an item ends without starting.
checked before the cancel branch and stays in the error chain.
.kept-<time>directory, or the install or upgrade is refused. Listing andthe leftover sweep ignore it.
backend.upgradegivesErrWorkerTooOld: no unhealthy mark, no attemptcounted. Docs and
.agents/distributed-seams.mdare updated.library items and the Assistant tool share
backendlib.JobRunner, whichholds a per-name guard and refuses with
run_activeduring a run. Therunner registers a cancel and removes it when the job ends.
in the store first, and
Saveis fenced by the runner. An item whoseoperation still has a status stays
running. A followed item whose statusstops changing for two minutes is checked fresh.
a run that is being created.
LRU. Its termination handler is removed when it exits.
HF_TOKEN=,OPENAI_API_KEY=, JSON"password":"x"andtoken shapes are removed. ANSI remnants and format characters (such as
U+202E) are dropped. The start-check output and error are sanitized in
local mode too.
unconfirmeditem that the server still checks shows as busy(
verifyingis now in the JSON). Older poll answers are dropped, andonEndedfires once. A review that cannot load says why once.starts, and the service pointer is an
atomic.Pointer.Closewaits forthe start, cancel and check goroutines.
that ends like a swap directory is refused.
Known limits
resolves to another name is not covered.
frontend falls back to a fresh check.
Testing
Go (
-tags nosqlite,purego_utp, PostgreSQL specs againstpostgres:16-alpine),specs passed:
upgraderun125,distributed40,endpoints/localai928,application463,endpoints/addons(auth) 216,galleryop220,gallery647,nodes1135,worker466,workerctl71,carrier319,routes280.-racepasses onupgraderun,updatenotifyanddistributed. The add-on inventory inscripts/addons/suites.jsonmatches thereal report.
make swaggergives no diff, and lint reports no issue. UI: 2055unit cases and the lint, i18n and colour gates pass; Playwright on the update,
review, inbox, nodes, placement, backends, add-ons and view-as specs: 694
passed, 14 skipped.
After rebasing onto master,
upgraderun,backendlib,gallery,endpoints/localai,applicationandnodespass again.Assisted-by: Claude:claude-opus-5-5